/**
 * 
 */
package org.conan.groupapp.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.conan.groupapp.framework.dao.IBaseDao;
import org.conan.groupapp.framework.entity.PageData;
import org.conan.groupapp.framework.service.impl.BaseServiceImpl;
import org.conan.groupapp.system.dao.IAuthorityDao;
import org.conan.groupapp.system.dao.IRoleAuthorityDao;
import org.conan.groupapp.system.dao.IRoleDao;
import org.conan.groupapp.system.dao.IUserDao;
import org.conan.groupapp.system.dao.IUserRoleDao;
import org.conan.groupapp.system.entity.Role;
import org.conan.groupapp.system.service.IRoleService;
import org.conan.groupapp.util.OperLogToRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 *
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
	
	@Autowired
	@Qualifier("userDaoImpl")
	private IUserDao iUserDao;
	
	@Autowired
	@Qualifier("roleDaoImpl")
	private IRoleDao iRoleDao;

	
	@Autowired
	@Qualifier("userRoleDaoImpl")
	private IUserRoleDao iUserRoleDao;
	
	@Autowired
	@Qualifier("authorityDaoImpl")
	private IAuthorityDao iAuthorityDao;
	
	@Autowired
	@Qualifier("roleAuthorityDaoImpl")
	private IRoleAuthorityDao iRoleAuthorityDao;
	
	
	@Override
	@Resource(name = "roleDaoImpl")
	public void setiBaseDao(IBaseDao<Role> iBaseDao) {
		this.iBaseDao = iBaseDao;
	}
	
	
	@Override
	@OperLogToRecord
	public Role save(Role t) throws Exception {
		return null;
	}

	@Override
	@OperLogToRecord
	public Role modify(Role t) throws Exception {
		return null;
	} 
	
	@Override
	@OperLogToRecord
	public int remove(Integer primaryKey) throws Exception {
		return 0;
	} 
	
	@SuppressWarnings("unchecked")
	@Override
	public PageData convertPageList(PageData pd){
		List<Role> newList = new ArrayList<Role>();
		for (Role role : (List<Role>)pd.getRows()) {
			newList.add(role);
		}
		pd.setRows(newList);
//		pd.setTableTitle(TAB_TITLE);
//		pd.setPageUrl(PAGE_URL);
		return pd;
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toPageJson(PageData pd) {
		JSONArray cellList = new JSONArray();
		for (Role role : (List<Role>)pd.getRows()) {
			JSONArray cell = new JSONArray();
//			cell.add(channel.getName());
//			cell.add(channel.getAlias());
//			cell.add(channel.getDescription());
//			cell.add(DateUtil.getDateTime("yyyy-MM-dd HH:mm:ss",channel.getAddTime()));
//			cell.add(DateUtil.getDateTime("yyyy-MM-dd HH:mm:ss",channel.getUpdateTime()));
//			cell.add(convertIsMainsiteChannelToString(channel.getIsMainsiteChannel()));
//			
//			JSONObject cellObj=new JSONObject();
//			cellObj.put("id",channel.getId().toString());
//			cellObj.put("cell",cell);
//			
//			cellList.add(cellObj);
		}
		JSONObject obj=new JSONObject();
//		obj.put("total",Integer.toString(totalPage));
//		obj.put("page",Integer.toString(currentPage));
//		obj.put("records",Integer.toString(totalRecords));
		obj.put("rows", cellList);
		System.out.println(obj);
		return obj.toString();
	}
	

	public IUserDao getiUserDao() {
		return iUserDao;
	}


	public void setiUserDao(IUserDao iUserDao) {
		this.iUserDao = iUserDao;
	}


	public IRoleDao getiRoleDao() {
		return iRoleDao;
	}


	public void setiRoleDao(IRoleDao iRoleDao) {
		this.iRoleDao = iRoleDao;
	}


	public IUserRoleDao getiUserRoleDao() {
		return iUserRoleDao;
	}


	public void setiUserRoleDao(IUserRoleDao iUserRoleDao) {
		this.iUserRoleDao = iUserRoleDao;
	}


	public IAuthorityDao getiAuthorityDao() {
		return iAuthorityDao;
	}


	public void setiAuthorityDao(IAuthorityDao iAuthorityDao) {
		this.iAuthorityDao = iAuthorityDao;
	}


	public IRoleAuthorityDao getiRoleAuthorityDao() {
		return iRoleAuthorityDao;
	}


	public void setiRoleAuthorityDao(IRoleAuthorityDao iRoleAuthorityDao) {
		this.iRoleAuthorityDao = iRoleAuthorityDao;
	}


}
